package com.quwan.config;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * @author Zeng Hai
 * @date 2021/6/5 19:51
 */
//@Component
public class LogTraceIdInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String idStr = IdWorker.getIdStr();
        MDC.put("logId", idStr);
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        MDC.remove("logId");
    }
}